package com.hnkywl.sts.service.sys;

import com.google.gson.Gson;
import com.hnkywl.sts.dao.sys.CdDao;
import com.hnkywl.sts.entity.sys.Cd;
import com.hnkywl.sts.entity.sys.Js;
import com.hnkywl.sts.util.BaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 说明：
 * 包:        com.hnkywl.sts.service.sys
 * 类描述:    菜单服务类
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Service
public class CdService {
    private CdDao cdDao;

    /**
     * 生成整个菜单树的Json串
     *
     * @return
     */
    public String getTreeJson() {
        List<Cd> cdList = cdDao.findAllRootCd();
        Map<String, String> treeParam = new HashMap<String, String>();
        treeParam.put("text", "mc");
        treeParam.put("expand", "true");
        treeParam.put("id", "id");
        treeParam.put("level", "ymcj");
        treeParam.put("children", "cdList");
        return BaseUtils.getTreeJson(cdList, treeParam);
    }

    /**
     * 生成整个菜单树的另一种形式Json串
     *
     * @return
     */
    public String getTreeJson2() {
        List<Cd> cdList = cdDao.findAll();
        Map<String, String> treeParam = new HashMap<String, String>();
        treeParam.put("text", "mc");
        treeParam.put("expand", "true");
        treeParam.put("id", "id");
        treeParam.put("pid", "fcd.id");
        return BaseUtils.getTreeJson(cdList, treeParam);
    }

    /**
     * 获得菜单下的所有页面元素json串
     *
     * @param cdId 菜单Id
     * @return
     */
    public String getYmys(Long cdId) {
        if (cdId == null)
            return "[]";
        Cd cd = cdDao.get(cdId);
        return "[" + BaseUtils.fetchCollectionToJson(cd.getYmysList(), "id", "mc") + "]";
    }

    /**
     * 获得菜单下的所有功能操作json串
     *
     * @param cdId 菜单Id
     * @return
     */
    public String getGncz(Long cdId) {
        if (cdId == null)
            return "[]";
        Cd cd = cdDao.get(cdId);
        return "[" + BaseUtils.fetchCollectionToJson(cd.getGnczList(), "id", "mc") + "]";
    }


    public List findCdByJs(Set<Long> jsSet) {
        return cdDao.findCdByJs(jsSet);
    }

    public List<Object[]> findBottomCdByJs(Set<Long> jsSet) {
        List<Object[]> list = cdDao.findBottomCdByJs(jsSet);
        return list;
    }

    @Autowired
    public void setCdDao(CdDao cdDao) {
        this.cdDao = cdDao;
    }
}
